import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const routes = [
	{
		path: '/wechat',
		name: 'index',
		meta: {
			title: '首页'
		},
		component: () => import('../views/index')
	},
	{
		path: '/wechat/authorization',
		name: 'authorization',
		component: () => import('../views/authorization')
	},
	{
		path: '/wechat/wallet',
		name: 'wallet',
		meta: {
			title: '钱包'
		},
		component: () => import('../views/wallet')
	},
	{
		path: '/wechat/near',
		name: 'near',
		meta: {
			title: '附近'
		},
		component: () => import('../views/near')
	},
	{
		path: '/wechat/my',
			name: 'my',
		meta: {
			title: '我的'
		},
		component: () => import('../views/my')
	},
	{
		path: '/wechat/wallet/detail',
		meta: {
			title: '详情'
		},
		component: () => import('../views/detail')
	},
	{
		path: '/wechat/wallet/cashout',
		meta: {
			title: '提现'
		},
		component: () => import('../views/cashout')
	}, {
		path: '/wechat/wallet/investMoney',
		meta: {
			title: '充值'
		},
		component: () => import('../views/investMoney')
	}, {
		path: '/wechat/myOrder',
		meta: {
			title: '我的订单'
		},
		component: () => import('../views/myOrder')
	}, {
		path: '/wechat/wallet/counpon',
		meta: {
			title: '我的优惠券'
		},
		component: () => import('../views/counpon')
	}, {
		path: '/wechat/wallet/regular',
		meta: {
			title: '使用规则'
		},
		component: () => import('../views/regular')
	}
]

// router.beforeEach(( to, from, next ) => {
//   if (to.name != 'auth') {//判断当前是否是新建的auth路由空白页面
//     let _token = sessionStorage.getItem('wechataccess_token');
//     if (!_token) {//如果没有token,则让它授权
//       //保存当前路由地址，授权后还会跳到此地址
//       sessionStorage.setItem('beforeUrl', to.fullPath);	  
//       //授权请求,并跳转http://m.water.ui-tech.cn/auth路由页面
//       window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx17b8934255384849&redirect_uri=http%3A%2F%2Fm.water.ui-tech.cn%2Fauth&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
//     } else {
//       next();
//     }
//   } else {
//     next();
//   }
// });



export default new Router({
	mode: 'history',  //去掉url中的#
	routes
})
